package com.ubaer.zsycz.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lsw.Base.BaseHolder;
import com.lsw.Base.BaseSimpleAdapter;
import com.ubaer.zsycz.R;
import com.ubaer.zsycz.model.OrderModel;

/**
 * Created by Administrator on 2018/9/26 0026.
 */

public class SearchResultAdapter extends BaseSimpleAdapter<OrderModel> {
    public SearchResultAdapter(Context context) {
        super(context);
    }

    @Override
    protected BaseHolder<OrderModel> getHolder() {
        return new BaseHolder<OrderModel>() {
            View view;
            //充值状态
            TextView tv_status;
            //处理
            TextView tV_chuli;
            //处理时间
            LinearLayout ll_time;
            TextView tv_time;
            //金额
            TextView tv_price;
            //卡号
            TextView tv_car_number;
            //订单号
            TextView tv_order_number;


            @Override
            public void bindViews(View parentView) {
                view = parentView.findViewById(R.id.view);
                tv_status = parentView.findViewById(R.id.tv_status);
                tV_chuli = parentView.findViewById(R.id.tV_chuli);
                ll_time = parentView.findViewById(R.id.ll_time);
                tv_time = parentView.findViewById(R.id.tv_time);
                tv_price = parentView.findViewById(R.id.tv_price);
                tv_car_number = parentView.findViewById(R.id.tv_car_number);
                tv_order_number = parentView.findViewById(R.id.tv_order_number);
            }

            @Override
            public void bindData(OrderModel item, int position) {
                if (position == 0) {
                    view.setVisibility(View.VISIBLE);
                } else {
                    view.setVisibility(View.GONE);
                }
                if (item.getStatus() == 0) {
                    tV_chuli.setVisibility(View.VISIBLE);
                    tv_status.setVisibility(View.GONE);
                    ll_time.setVisibility(View.GONE);
                } else if (item.getStatus() == 1) {
                    tV_chuli.setVisibility(View.GONE);
                    tv_status.setVisibility(View.VISIBLE);
                    ll_time.setVisibility(View.VISIBLE);
                    tv_status.setText("充值成功");
                    tv_status.setTextColor(context.getResources().getColor(R.color.color_53913E));
                    tv_time.setText(item.getCreated_at());
                } else if (item.getStatus() == 2) {
                    tV_chuli.setVisibility(View.GONE);
                    tv_status.setVisibility(View.VISIBLE);
                    ll_time.setVisibility(View.VISIBLE);
                    tv_status.setText("充值失败");
                    tv_status.setTextColor(context.getResources().getColor(R.color.color_C73922));
                    tv_time.setText(item.getCreated_at());
                }
                tv_order_number.setText(item.getOrder_no());
                tv_car_number.setText(item.getCard_num());
                tv_price.setText(item.getMoney());
                tV_chuli.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (adapterRefresh != null)
                            adapterRefresh.onRefreshAdapter(position, 1);
                    }
                });
            }
        };
    }

    @Override
    protected int getLayoutResource() {
        return R.layout.item_search_result;
    }
}
